package com.zjz.studynotes;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.ComponentActivity;
import androidx.annotation.Nullable;

import com.zjz.studynotes.bean.LoginUserInfo;
import com.zjz.studynotes.db.StudyNotesDb;

/**
 * Description: 注册页面
 * Author: zjz
 * Date:2025/5/5 13:06
 */
public class RegisterActivity extends ComponentActivity {
    private EditText mEtUsername;
    private EditText mEtPassword;
    private Button mBtnConfirm;
    private Button mBtnCancel;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_register);


        mEtUsername = findViewById(R.id.et_user_name);
        mEtPassword = findViewById(R.id.et_password);
        mBtnConfirm = findViewById(R.id.btn_confirm);
        mBtnCancel = findViewById(R.id.btn_cancel);


        mBtnConfirm.setOnClickListener(view -> {
            register();
        });

        mBtnCancel.setOnClickListener(view -> finish());
    }

    private void register() {
        if (TextUtils.isEmpty(mEtUsername.getText().toString())) {
            Toast.makeText(this, "请输入用户名", Toast.LENGTH_SHORT).show();
            return;
        }

        if (TextUtils.isEmpty(mEtPassword.getText().toString())) {
            Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
            return;
        }

        LoginUserInfo info = new LoginUserInfo();
        info.setUserName(mEtUsername.getText().toString());
        info.setPassword(mEtPassword.getText().toString());
        StudyNotesDb.getInstance(this).getLoginUerInfoDao().insert(info);

        Toast.makeText(this, "请登录", Toast.LENGTH_SHORT).show();

        finish();
    }
}
